package com.hkfn.rfb.rfb.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.hkfn.rfb.R;
import com.hkfn.rfb.common.activity.BaseActivity;
import com.hkfn.rfb.common.fragment.BaseFragment;
import com.hkfn.rfb.databinding.FRfbSystemOverviewBinding;

public class RfbSystemOverviewFragment extends BaseFragment {

    private BaseActivity activity;

    private Bundle bundle;

    private FRfbSystemOverviewBinding fRfbSystemOverviewBinding;

    private int currentPage = -1;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        activity = getMyActivity();
        bundle = getArguments();
        fRfbSystemOverviewBinding = FRfbSystemOverviewBinding.inflate(inflater, container, false);
        initView();
        return fRfbSystemOverviewBinding.getRoot();
    }

    private void initView() {
        fRfbSystemOverviewBinding.tvBatterySystem.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                selectPage(0);
            }
        });
        fRfbSystemOverviewBinding.tvTemperatureSystem.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                selectPage(1);
            }
        });
        fRfbSystemOverviewBinding.tvGasSystem.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                selectPage(2);
            }
        });

        selectPage(0);
    }

    private void selectPage(int selectPage){
        if (selectPage == currentPage){
            return;
        }
        switch (currentPage){
            case 0:
                fRfbSystemOverviewBinding.tvBatterySystem.setBackground(activity.getResources().getDrawable(R.drawable.shape_rfb_system_overview_change_btn_unselect));
                fRfbSystemOverviewBinding.includeBatterySystem.getRoot().setVisibility(View.GONE);
                break;
            case 1:
                fRfbSystemOverviewBinding.tvTemperatureSystem.setBackground(activity.getResources().getDrawable(R.drawable.shape_rfb_system_overview_change_btn_unselect));
                fRfbSystemOverviewBinding.includeTemperatureSystem.getRoot().setVisibility(View.GONE);
                break;
            case 2:
                fRfbSystemOverviewBinding.tvGasSystem.setBackground(activity.getResources().getDrawable(R.drawable.shape_rfb_system_overview_change_btn_unselect));
                fRfbSystemOverviewBinding.includeGasSystem.getRoot().setVisibility(View.GONE);
                break;
        }
        currentPage = selectPage;
        switch (currentPage){
            case 0:
                fRfbSystemOverviewBinding.tvBatterySystem.setBackground(activity.getResources().getDrawable(R.drawable.shape_rfb_system_overview_change_btn_select));
                fRfbSystemOverviewBinding.includeBatterySystem.getRoot().setVisibility(View.VISIBLE);
                break;
            case 1:
                fRfbSystemOverviewBinding.tvTemperatureSystem.setBackground(activity.getResources().getDrawable(R.drawable.shape_rfb_system_overview_change_btn_select));
                fRfbSystemOverviewBinding.includeTemperatureSystem.getRoot().setVisibility(View.VISIBLE);
                break;
            case 2:
                fRfbSystemOverviewBinding.tvGasSystem.setBackground(activity.getResources().getDrawable(R.drawable.shape_rfb_system_overview_change_btn_select));
                fRfbSystemOverviewBinding.includeGasSystem.getRoot().setVisibility(View.VISIBLE);
                break;
        }
    }

}
